#!/bin/env bash

#功能: 生成差异补丁文件并对缺陷进行打补丁
#1. 单个文件生成补丁文件
diff checksum.sh crypt.sh    #输出差异到标准输出
diff -u checksum.sh crypt.sh #以统一的格式输出差异
diff -u checksum.sh crypt.sh > diff.patch #单个文件生成补丁(crypt.sh是新文件)

#2. 单个文件打补丁
patch checksum.sh diff.patch #向老checksum.sh合入补丁
patch checksum.sh < diff.patch

#3. 文件夹生成补丁
diff -urN 001-class 002-class > diff.patch #-r递归操作 - N不存在的文件视为空文件

#4. 文件夹打补丁
patch -p1 -d 001-class < diff.patch  #-p1忽略第一级目录 -d进入001-class目录
patch -p1 -b -d 001-class < diff.patch #合入补丁前先备份为*.orig文件
patch -p1 -b --suffix=.bak -d 001-class < diff.patch #合入补丁后备份文件以.bak命名


